package com.myapp.api.mapper;

import com.myapp.api.entity.Admin;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface AdminMapper {
    @Delete({
        "delete from admin",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into admin (id, Account, ",
            "Username, Pwd, LoginTime, ",
            "LoginIP, Role, CreateTime, ",
            "UpdateTime, AuthToken)",
            "values (#{id,jdbcType=INTEGER}, #{account,jdbcType=VARCHAR}, ",
            "#{username,jdbcType=VARCHAR}, #{pwd,jdbcType=VARCHAR}, #{logintime,jdbcType=TIMESTAMP}, ",
            "#{loginip,jdbcType=VARCHAR}, #{role,jdbcType=VARCHAR}, #{createtime,jdbcType=TIMESTAMP}, ",
            "#{updatetime,jdbcType=TIMESTAMP}, #{authtoken,jdbcType=LONGVARCHAR})"
    })
    int insert(Admin record);

    @InsertProvider(type=AdminSqlProvider.class, method="insertSelective")
    int insertSelective(Admin record);

    @Select({
        "select",
            "id, Account, Username, Pwd, LoginTime, LoginIP, Role, CreateTime, UpdateTime, ",
            "AuthToken",
        "from admin",
            "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column = "Account", property = "account", jdbcType = JdbcType.VARCHAR),
            @Result(column = "Username", property = "username", jdbcType = JdbcType.VARCHAR),
        @Result(column="Pwd", property="pwd", jdbcType=JdbcType.VARCHAR),
        @Result(column="LoginTime", property="logintime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="LoginIP", property="loginip", jdbcType=JdbcType.VARCHAR),
            @Result(column = "Role", property = "role", jdbcType = JdbcType.VARCHAR),
        @Result(column="CreateTime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column = "UpdateTime", property = "updatetime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "AuthToken", property = "authtoken", jdbcType = JdbcType.LONGVARCHAR)
    })
    Admin selectByPrimaryKey(Integer id);

    @UpdateProvider(type=AdminSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Admin record);

    @Update({
        "update admin",
            "set Account = #{account,jdbcType=VARCHAR},",
            "Username = #{username,jdbcType=VARCHAR},",
            "Pwd = #{pwd,jdbcType=VARCHAR},",
            "LoginTime = #{logintime,jdbcType=TIMESTAMP},",
            "LoginIP = #{loginip,jdbcType=VARCHAR},",
            "Role = #{role,jdbcType=VARCHAR},",
            "CreateTime = #{createtime,jdbcType=TIMESTAMP},",
            "UpdateTime = #{updatetime,jdbcType=TIMESTAMP},",
            "AuthToken = #{authtoken,jdbcType=LONGVARCHAR}",
            "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKeyWithBLOBs(Admin record);

    @Update({
            "update admin",
            "set Account = #{account,jdbcType=VARCHAR},",
            "Username = #{username,jdbcType=VARCHAR},",
            "Pwd = #{pwd,jdbcType=VARCHAR},",
            "LoginTime = #{logintime,jdbcType=TIMESTAMP},",
            "LoginIP = #{loginip,jdbcType=VARCHAR},",
            "Role = #{role,jdbcType=VARCHAR},",
          "CreateTime = #{createtime,jdbcType=TIMESTAMP},",
          "UpdateTime = #{updatetime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Admin record);

    @Select({
            "select",
            "id, Account, Username, Pwd, LoginTime, LoginIP, Role, CreateTime, UpdateTime, ",
            "AuthToken",
            "from admin"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column = "Account", property = "account", jdbcType = JdbcType.VARCHAR),
            @Result(column = "Username", property = "username", jdbcType = JdbcType.VARCHAR),
            @Result(column="Pwd", property="pwd", jdbcType=JdbcType.VARCHAR),
            @Result(column="LoginTime", property="logintime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="LoginIP", property="loginip", jdbcType=JdbcType.VARCHAR),
            @Result(column = "Role", property = "role", jdbcType = JdbcType.VARCHAR),
            @Result(column="CreateTime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column = "UpdateTime", property = "updatetime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "AuthToken", property = "authtoken", jdbcType = JdbcType.LONGVARCHAR)
    })
    List<Admin> getAdmins();

    @Select({
            "select",
            "id, Account, Username, Pwd, LoginTime, LoginIP, Role, CreateTime, UpdateTime, ",
            "AuthToken",
            "from admin",
            "where Account = #{account,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "Account", property = "account", jdbcType = JdbcType.VARCHAR),
            @Result(column = "Username", property = "username", jdbcType = JdbcType.VARCHAR),
            @Result(column = "Pwd", property = "pwd", jdbcType = JdbcType.VARCHAR),
            @Result(column = "LoginTime", property = "logintime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "LoginIP", property = "loginip", jdbcType = JdbcType.VARCHAR),
            @Result(column = "Role", property = "role", jdbcType = JdbcType.VARCHAR),
            @Result(column = "CreateTime", property = "createtime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "UpdateTime", property = "updatetime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "AuthToken", property = "authtoken", jdbcType = JdbcType.LONGVARCHAR)
    })
    Admin getAdminByAccount(String account);

    @Select({
            "select count(*)",
            "id, Account, Username, Pwd, LoginTime, LoginIP, Role, CreateTime, UpdateTime, ",
            "AuthToken",
            "from admin",
            "where Account = #{account,jdbcType=VARCHAR}"
    })
    Integer getAdminByOneAccount(String account);
}